<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <fieldset class="layui-elem-field">
        <legend>批发会员审核</legend>
        <div class="layui-field-box">
            <div class="layui-card">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">会员信息</label>
                            <div class="layui-input-inline">
                                <input type="text" name="info" placeholder="请输入会员昵称或手机号" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-inline">
                                <select name="status">
                                    <option value="">选择状态</option>
                                    <option value="0">待审核</option>
                                    <option value="1">审核通过</option>
                                    <option value="2">审核拒绝</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            </button>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body">
                    <table id="demo" lay-filter="demo"></table>
                    <script type="text/html" id="package">
                        {{d.package}}
                    </script>
                    <script type="text/html" id="time">
                        {{ formatDateTime(d.time) }}
                    </script>
                    <script type="text/html" id="status">
                        {{# if (d.status == 0){ }}
                        <button class="layui-btn layui-btn-xs layui-bg-orange">待审核</button>
                        {{# }else if(d.status == 1){ }}
                        <button class="layui-btn layui-btn-xs layui-bg-blue">已通过</button>
                        {{# }else{ }}
                        <button class="layui-btn layui-btn-xs layui-bg-red">已拒绝</button>
                        {{# } }}
                    </script>
                    <script type="text/html" id="table-content-list">
                        {{# if (d.status == 0){ }}
                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="shenhe"><i class="layui-icon layui-icon-survey"></i>审核</a>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </fieldset>

</div>
<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'useradmin', 'table'], function(){
        var $ = layui.$,
                form = layui.form,
                table = layui.table;

        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('demo', {
                url: "{:url('User/pifa_operate')}",
                where: field,
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //执行渲染
        table.render({
            elem: '#demo',
            url: "{:url('User/pifa_operate')}",
            method: 'post',
            cols: [[
                {field: 'uid', title: '会员昵称'},
                {field: 'phone', title: '手机号'},
                {field: 'time', title: '申请时间', templet: "#time"},
                {field: 'status', title: '状态', templet: "#status"},
                {fixed: 'right', title: '操作', width: 250, align:'center', toolbar: '#table-content-list'}
            ]],
            page: {
                limits: [10, 20, 30, 40, 50]
            }
        });

        //监听事件
        table.on('tool(demo)', function(obj){
            var id = obj.data.id;
            var layEvent = obj.event;
            if (layEvent === 'shenhe'){
                layer.confirm('审核操作', {
                    icon: 3,
                    title:'审核',
                    offset: ['25%', '35%'],
                    btn: ['通过', '拒绝']
                }, function(index){
                    $.post("{:url('User/pifa_shenhe')}", {id:id,type:1}, function (e) {
                        if (e == 1){
                            layer.msg('审核成功', {offset: ['30%', '40%']});
                            setTimeout(function () {
                                table.reload('demo'); //重载表格
                                layer.close(index); //再执行关闭
                            }, 500)
                        }else{
                            layer.msg('审核失败', {offset: ['30%', '40%']});
                        }
                    });
                }, function(index){
                    $.post("{:url('User/pifa_shenhe')}", {id:id,type:2}, function (e) {
                        if (e == 1){
                            layer.msg('拒绝成功', {offset: ['30%', '40%']});
                            setTimeout(function () {
                                table.reload('demo'); //重载表格
                                layer.close(index); //再执行关闭
                            }, 500)
                        }else{
                            layer.msg('拒绝失败', {offset: ['30%', '40%']});
                        }
                    });
                })
            }
        });
    });


    //php时间戳用js转换为yyyy-mm-dd
    function formatDateTime(timeStamp) {
        var date = new Date();
        date.setTime(timeStamp * 1000);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        var h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        var minute = date.getMinutes();
        var second = date.getSeconds();
        minute = minute < 10 ? ('0' + minute) : minute;
        second = second < 10 ? ('0' + second) : second;
        return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
    }
</script>
</body>
</html>
